package group.program.Controller;

import group.program.Service.LoginService;
import group.program.pojo.trafficPojo.Result;
import group.program.pojo.trafficPojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoginController {
    @Autowired
    private LoginService loginService;

    @PostMapping("/login")
    public Result login(@RequestParam String user_name, @RequestParam String password) {
        // 调用登录服务进行验证
        User loginSuccessful = loginService.login(user_name, password);
        if(loginSuccessful!=null){
            System.out.println(loginSuccessful.toString());
            return Result.success("登录成功");
        }

        return Result.error("用户名或密码错误");
    }
}
